package com.tmt.im.manager.controller.api;

import com.alibaba.fastjson2.JSONObject;
import com.tmt.im.common.Constant;
import com.tmt.springboot.common.restful.ResultWrapper;
import com.tmt.im.common.pojo.ChatDataKey;
import com.tmt.im.manager.service.IMUserService;
import com.tmt.springboot.common.restful.ExecuteResult;
import com.tmt.springboot.common.restful.IExecuteResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteMessaging;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

/**
 * @Description TODO
 * @Author wuyi
 * @Date 2024/8/4 11:18
 * @Version 1.0
 **/
@Async("asyncTaskExecutor")
@Tag(name = "测试相关接口", description = "测试相关接口")
@RestController
@RequestMapping("${api-url-prefix}/test")
public class TestController {

    private final Ignite ignite;

    private final IMUserService imUserService;

    public TestController(Ignite ignite,
                          IMUserService imUserService) {
        this.ignite = ignite;
        this.imUserService = imUserService;
    }

    @Operation(summary = "打招呼接口", description = "打招呼接口")
    @GetMapping(value = "/hello")
    public CompletableFuture<IExecuteResult<ResultWrapper<Boolean>>> loadUserList() {
        IgniteMessaging igniteMessaging = ignite.message(ignite.cluster().forRemotes());
        JSONObject json = new JSONObject();
        json.put("eventType", 0L);
        igniteMessaging.sendOrdered(Constant.YUN_XIN_MSG_TOPIC_ID, json, 0);
        igniteMessaging.sendOrdered(2222L, new ChatDataKey(1L, 2222L), 0);
        return CompletableFuture.completedFuture(ResultWrapper.from(ExecuteResult.success(true)));
    }

}
